package com.hxzy.tms.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.Set;

import com.hxzy.tms.ExtendsActionSupport;
import com.hxzy.tms.SessionHolder;
import com.hxzy.tms.entity.Project;
import com.hxzy.tms.entity.Task;
import com.hxzy.tms.entity.Team;
import com.hxzy.tms.entity.User;
import com.hxzy.tms.service.ServiceResult;
import com.hxzy.tms.service.TaskService;
import com.hxzy.tms.service.TeamService;

public class TaskAction extends ExtendsActionSupport{
  private static final long serialVersionUID = -7824115818037068463L;
    private TaskService taskService;
    private Task task;
	private TeamService teamService;
	private Date gmtStart;
	private Date gmtFinished;
    private Team team;
	private Set<Project> projects;
    //发布任务
	  public String publish(){
		// User user=SessionHolder.get();
		   if(isPost()){
			   ServiceResult<Task> result=taskService.createTask(task.getTitle(), task.getDesc(), task.getAttachmentUrl(), 
					   gmtStart, gmtFinished,1L,1L,1L);
		         if(result.status==1){
		        	 return SUCCESS;
		         }
		         switch (result.status) {
		        case 0:
		        	addActionMessage( result.message);
		        	 break;
				case -1:
					addFieldError("title", result.message);
					break;
				case -2:
					addFieldError("title", result.message);
					break;
				case -3:
					addFieldError("gmtfinished", result.message);
					break;
				}
		   }
		   
		return INPUT;  
	  }
//修改任务
	  public String revise(){
		  User user=SessionHolder.get();
		   if(isPost()){
			   ServiceResult<Task> result=taskService.modifyTask(task.getTitle(), task.getDesc(), task.getAttachmentUrl(), gmtStart,  gmtFinished,user.getId(),team.getId(),task.getId());
		         if(result.status==1){
		        	 addActionMessage("任务发布成功");
		        	 return SUCCESS;
		         }
		         switch (result.status) {
		         case 0:
			        	addActionMessage( result.message);
			        	 break;
				case -1:
					addFieldError("title", result.message);
					break;
				case -2:
					addFieldError("title", result.message);
					break;
				case -3:
					addFieldError("gmtfinished", result.message);
					break;
				case -4:
					addFieldError("gmtfinished", result.message);
					break;
				}
		   }
		   
		return INPUT;  
	  }
	  //查看某项目发布的任务
	  public String list(){
	      User user=SessionHolder.get();
		  ServiceResult<ArrayList<Task>> result=taskService.mylists(1L, 1L, 1L);
		 switch (result.status) {
		case -1:
			addFieldError("title", result.message);
			break;
		case -2:
			addFieldError("title", result.message);
			break;
		}
		  return SUCCESS;
		    
	  }
	  
	public TaskService getTaskService() {
		return taskService;
	}
	public void setTaskService(TaskService taskService) {
		this.taskService = taskService;
	}

	public Task getTask() {
		return task;
	}
	public void setTask(Task task) {
		this.task = task;
	}

	public TeamService getTeamService() {
		return teamService;
	}
	public void setTeamService(TeamService teamService) {
		this.teamService = teamService;
	}
	public Date getGmtStart() {
		return gmtStart;
	}
	public void setGmtStart(Date gmtStart) {
		this.gmtStart = gmtStart;
	}
	public Date getGmtFinished() {
		return gmtFinished;
	}
	public void setGmtFinished(Date gmtFinished) {
		this.gmtFinished = gmtFinished;
	}
	public Team getTeam() {
		return team;
	}
	public void setTeam(Team team) {
		this.team = team;
	}
	public Set<Project> getProjects() {
		return projects;
	}
	public void setProjects(Set<Project> projects) {
		this.projects = projects;
	}



}
